# 开发人员  ：  DanXinShang
# 开发时间  ：  2022/3/13  7:19 下午
# 文件名称  :  modes.py
# 开发工具  :  PyCharm
from sqlalchemy.dialects.mysql import NVARCHAR, INTEGER, DATETIME, DATE, TIME
from sqlalchemy import Column
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from config import DB_URL
import datetime

Base = declarative_base()  # 生成orm基类


class CheckLog(Base):
    __tablename__ = 'check_log'

    check_id = Column(NVARCHAR(100), primary_key=True, name="check_id", comment="考勤编号")
    timestamp = Column(INTEGER, primary_key=True, default=0, name="timestamp", comment="时间戳int：10位")
    user_code = Column(NVARCHAR(10), index=True, nullable=False, name="user_code", comment="员工代码")
    user_name = Column(NVARCHAR(50), nullable=False, name="user_name", comment="用户姓名")
    check_in_time = Column(DATETIME, index=True, nullable=False, name="check_in_time", comment="打卡时间，日期时间类型")
    device = Column(NVARCHAR(100), nullable=False, name="device", comment="设备名称")
    l_title = Column(NVARCHAR(100), name="l_title", comment="打卡地点")
    l_detail = Column(NVARCHAR(100), name="l_detail", comment="打卡地点详情")
    group_name = Column(NVARCHAR(100), name="group_name", comment="数据来源")
    checkin_type = Column(NVARCHAR(100), name="checkin_type", comment='打卡类型')


class DateRecord(Base):
    __tablename__ = 'date_record'

    date_id = Column(NVARCHAR(20), primary_key=True, name="date_id", comment="日期标识")
    table_flag = Column(NVARCHAR(20), primary_key=True, name="table_flag", comment="插入表标识")
    date_flag = Column(DATE, nullable=False, name="date_flag", comment="日期")


class UserCheck(Base):
    __tablename__ = 'user_check'

    user_code = Column(NVARCHAR(10), nullable=False, primary_key=True, name="user_code", comment="工号")
    user_name = Column(NVARCHAR(50), nullable=False, name="user_name", comment="姓名")
    zk_id = Column(INTEGER, default=0, name="zk_id", comment="中控id")
    wx_id = Column(NVARCHAR(20), name="wx_id", comment="微信id")
    check_type = Column(INTEGER, name="check_type", default=0, nullable=False, comment="考勤类型,0:不考勤，1:中控，2:微信")
    check_start = Column(TIME, name="check_start", default=datetime.time(9, 0), nullable=False, comment="上班时间")
    check_end = Column(TIME, name="check_end", default=datetime.time(17, 30), nullable=False, comment="下班时间")
    line_flag = Column(INTEGER, name="line_flag", default=1, nullable=False, comment="条线：0:前线，1:后线")
    is_valid = Column(INTEGER, name="is_valid", default=0, nullable=False, comment="账户状态")
    email = Column(NVARCHAR(50), nullable=False, name="email", comment="邮箱")


class CheckInDaily(Base):
    __tablename__ = 'check_in_daily'

    user_code = Column(NVARCHAR(10), nullable=False, primary_key=True, name="user_code", comment="工号")
    date_id = Column(DATE, nullable=False, primary_key=True, name="date_id", comment="日期")
    user_name = Column(NVARCHAR(50), nullable=False, name="user_name", comment="姓名")
    shifts = Column(NVARCHAR(20), name="shifts", comment="班次")
    in_check = Column(TIME, nullable=True, name="in_check", comment="上班打卡")
    in_check_desc = Column(NVARCHAR(20), name="in_check_desc", comment="上班打卡")
    out_check = Column(TIME, nullable=True, name="out_check", comment="下班打卡")
    out_check_desc = Column(NVARCHAR(20), name="out_check_desc", comment="上班打卡")
    state = Column(INTEGER, nullable=False, name="state", comment="状态")


Base.metadata.create_all(create_engine(DB_URL, echo=True))
